home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10681 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: solon.com!not-for-mail
  2. From: seebs@solutions.solon.com (Peter Seebach)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: operator % - compiler error
  5. Date: 19 Mar 1996 06:27:22 -0600
  6. Organization: Usenet Fact Police (Undercover)
  7. Message-ID: <4im97a$dm5@solutions.solon.com>
  8. References: <4ihuuh$6ul@hatathli.csulb.edu> <314DD835.33BE@willows.com>
  9. NNTP-Posting-Host: solutions.solon.com
  10.  
  11. In article <314DD835.33BE@willows.com>,
  12. Tarang Deshpande  <tarang@willows.com> wrote:
  13. >David Cho wrote:
  14. >> When I try to compile, I get an erro message for the following line:
  15. >> x=663608941*y%pow(2,32)  /*I want remainder*/
  16. >> But the error message says "illegal use of floating point".  What does
  17. >> that mean?  Isn't % used a an operator to calcuate the remainder?
  18.  
  19. >Although the % operator calculates the remainder it does so for two
  20. >ints and not two floats or double.  You need to change your code to
  21.  
  22. >x = ( long )( 663608941 * y ) % ( long )( pow ( 2, 32 ) );
  23.  
  24. As you correctly demonstrate, it actually works on two integral types,
  25. not two ints.  The (long) on the left is probably redundant.
  26.  
  27. Note that it's quite possible that (long) pow(2, 32) is 0.  It's also
  28. possible that it causes a crash.
  29.  
  30. -s
  31. -- 
  32. Peter Seebach - seebs@solon.com - Copyright 1996 Peter Seebach.
  33. C/Unix wizard -- C/Unix questions? Send mail for help.  No, really!
  34. FUCK the communications decency act.  Goddamned government.  [literally.]
  35. The *other* C FAQ - http://www.solon.com/~seebs/c/c-iaq.html
  36.